package org.example.mybatis.test;

import io.netty.channel.Channel;
import org.example.gateway.session.SessionServer;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ApiTest {

    private final static Logger log = LoggerFactory.getLogger(ApiTest.class);

    @Test
    public void test() throws ExecutionException, InterruptedException {
        log.info("xxx");
        SessionServer sessionServer = new SessionServer();

        Future<Channel> future = Executors.newFixedThreadPool(2).submit(sessionServer);
        Channel channel = future.get();
        if (null == channel) {
            throw new RuntimeException("netty server start error. channel is null");
        }

        while (!channel.isActive()) {
            log.info("NettyServer启动服务中……");
            Thread.sleep(500);
        }

        log.info("NettyServer启动服务完成. {}", channel.localAddress());
        Thread.sleep(Long.MAX_VALUE);
    }
}
